﻿using Gx.Common;
using Gx.Common.Core;
using Gx.Dal.Manage;
using Gx.Model;
using Gx.Model.Entity;
using Gx.Model.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;


namespace Gx.Bll.Manage
{
    public class LKCostTypesBll
    {

        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        public List<LKCostTypes> GetLKCostTypess()
        {
            LKCostTypesDal dal = new LKCostTypesDal();
            return dal.GetAll().ToList();
        }

        /// <summary>
        /// 新增费用类别
        /// </summary>
        /// <param name="lKCostTypes"></param>
        /// <returns></returns>
        public ReturnModel AddLKCostTypes(LKCostTypes lKCostTypes)
        {
            LKCostTypesDal dal = new LKCostTypesDal();

            var any = dal.AnyName(lKCostTypes.CostTypeName);
            if (any)
            {
                return new ReturnModel { Success = false, Msg = "名称已存在" };
            }


            lKCostTypes.CreateTime = DateTime.Now;
            lKCostTypes.CreateUserId = LoginHelper.GetUserId();
            lKCostTypes.CreateUser = LoginHelper.UserName();
            var result= dal.Insert(lKCostTypes);
            return new ReturnModel { Success = result, Msg = result ? "新增成功" : "新增失败" };
        }

        /// <summary>
        /// 编辑费用类别
        /// </summary>
        /// <param name="lKCostTypes"></param>
        /// <returns></returns>
        public bool EditLKCostTypes(LKCostTypes lKCostTypes)
        {
            LKCostTypesDal dal = new LKCostTypesDal();
            var cus = dal.Get(lKCostTypes.Id);
            if (cus == null)
            {
                return false;
            }
            lKCostTypes.CreateTime = cus.CreateTime;
            lKCostTypes.CreateUserId = cus.CreateUserId;
            lKCostTypes.CreateUser = cus.CreateUser;
            return dal.Update(lKCostTypes);
        }

        /// <summary>
        /// 删除费用类别
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteLKCostTypes(int id)
        {
            LKCostTypesDal dal = new LKCostTypesDal();
            return dal.DeleteById(id);
        }
    }
}

